package com.example.administrator.basepro.ui.act;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.example.administrator.basepro.R;
import com.example.administrator.basepro.base.BaseActivity;
import com.example.administrator.basepro.model.bean.TableBean;
import com.example.administrator.basepro.model.bean.TableOpeBean;
import com.example.administrator.basepro.model.bean.TableOpeBeanData;
import com.example.administrator.basepro.ui.contract.SecureShowContract;
import com.example.administrator.basepro.ui.contract.SubmitSecureContract;
import com.example.administrator.basepro.ui.presenter.SecureShowPresenter;
import com.example.administrator.basepro.utils.ActivityUtils;

import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2017/9/1 0001.
 */

public class SecureShowActivity extends BaseActivity<SecureShowPresenter> implements SecureShowContract.View{

    @BindView(R.id.listview)
    ListView listView;

    @BindView(R.id.empty_view)
    TextView empty_view;
    @Override
    protected void initInject() {
        getActivityComponent().inject(this);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_secureshow;
    }

    @Override
    protected void initEventAndData() {
        empty_view.setVisibility(View.GONE);
        mPresenter.getSecureInfo();

    }

    @Override
    public void showSecureInfo(TableBean data) {
        if (data==null)return;
        final List<TableBean.MapListBean> list = data.getMapList();
        if (list.size()==0){
            empty_view.setVisibility(View.VISIBLE);
        }
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                TableBean.MapListBean mapListBean = list.get(position);
                Intent intent=new Intent(SecureShowActivity.this,SecureDetailActivity.class);
                Bundle bundle=new Bundle();
                bundle.putSerializable("bean",mapListBean);
                intent.putExtras(bundle);
                startActivity(intent);
            }
        });
        listView.setAdapter(new MyAdapter(list));
    }

    class MyAdapter extends BaseAdapter{
        List<TableBean.MapListBean> list;

        public MyAdapter(List<TableBean.MapListBean> list) {
            this.list = list;
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder=null;
            if (convertView==null){
                holder=new ViewHolder();
                convertView=View.inflate(parent.getContext(),R.layout.item_info,null);
                holder.itemText= (TextView) convertView.findViewById(R.id.list_item);
                convertView.setTag(holder);
            }else {
                holder= (ViewHolder) convertView.getTag();
            }
            holder.itemText.setText(list.get(position).getTitle());
            return convertView;
        }
    }

    class ViewHolder {
        TextView itemText;
    }
}
